Delete identity pool identities

Descripcion

Script para eliminar las identidades quey haya creadas en un identity pool.

Script

Tenemos que instalar el siguiente paquete:

npm install @aws-sdk/client-cognito-identity

Tenemos que cambiar los valores:

El usuario que estemos usando tiene que tener los siguientes permisos:

import { CognitoIdentityClient, ListIdentitiesCommand, DeleteIdentitiesCommand } from "@aws-sdk/client-cognito-identity";

const client = new CognitoIdentityClient({
  region: 'REGION',
  credentials: {
      accessKeyId: 'ACCESS_KEY',
      secretAccessKey: 'SECRET_KEY',
    }
});

//let nextToken = ""

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

do{
    const input = {
        IdentityPoolId: "IDENTITY_POOL_ID",
        MaxResults: Number(60),
        //NextToken: nextToken ?  nextToken:null,
    };
    

    const command = new ListIdentitiesCommand(input);
    const response = await client.send(command);

    //nextToken = response.NextToken;

    let idList = []
    response.Identities.forEach( identitie => {
        idList.push(identitie.IdentityId)
    })
        
    console.log(idList[1]) //Solo para ver que hay progreso

    const inputId = { 
        IdentityIdsToDelete: idList,
    };
    const commandId = new DeleteIdentitiesCommand(inputId);
    try{
        const response = await client.send(commandId);
    }
    catch(err){
        console.error("TOO MANY REQUESTS !!!!")
        
    }
    await sleep(100);

}
while(true)
Tags

AWS | Identity pool